package com.yang.jdbc;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @author yangjiming
 * @create 2021-03-26 10:27
 */
public class JdbcDemo01 {
    public static void main(String[] args) throws Exception{
        //1.加载驱动程序
        Class.forName("com.mysql.jdbc.Driver");
        //2.获得数据库连接
        String url="jdbc:mysql://master:3306/shujia";
        String username="root";
        String password="123456";
        Connection conn = DriverManager.getConnection(url, username, password);
        //3.通过数据库连接操作数据库，实现增删改查
        String sql = "select * from emp";
        Statement statement = conn.createStatement();
        ResultSet rs = statement.executeQuery(sql);
        //4.处理数据库返回的结果
        while(rs.next()){
            System.out.println(rs.getString("ename"));
        }
        //5.关闭资源
        rs.close();
        statement.close();
        conn.close();
    }
}
